import sympy as sp
from sympy import symbols, integrate, sqrt, atan, sin, cos

# 定义符号变量
a, x = symbols('a x', real=True, positive=True)

expr5 = sqrt(a**2 - x**2)

# 例5：计算定积分 ∫₀ᵃ √(a²-x²) dx
print("例5：计算定积分 ∫₀ᵃ √(a²-x²) dx")
definite_integral = integrate(expr5, (x, 0, a))
print(f"定积分结果：{definite_integral}")

# 验证特殊情况 (a=1)
print("\n验证特殊情况 (a=1)：")
definite_integral_special = integrate(sqrt(1 - x**2), (x, 0, 1))
print(f"∫₀¹ √(1-x²) dx = {definite_integral_special}")
print(f"数值结果：{definite_integral_special.evalf()}")